#ifndef DAEMONOPTIONS_H_INCLUDED
#define DAEMONOPTIONS_H_INCLUDED

#include <Ape/IO/Console.h>

#include <Ape/String.h>
#include <Ape/IO/FS/Path.h>

namespace MultiplexD {
	#define B(n, v) \
		StdOut << n << (v ? L"true" : L"false") << NewLine;
	#define S(n, v) \
		StdOut << n << (Ape::String(L"'") + v + Ape::String(L"'")) << NewLine;
	
	using namespace Ape;
	using Ape::IO::FS::Path;
	
	struct DaemonOptions {
		bool	ActAsDaemon;
		String	WorkingDirectory;
		String	ConfigFile;
		String	LogFile;
		String	PidFile;
		bool	Verbose;
		
		void Reset() {
			ActAsDaemon = false;
			WorkingDirectory = L".";
			ConfigFile = L"";
			LogFile = L"";
			PidFile = L"";
			Verbose = false;
		}
		
		const Path ResolvePath(const Path& path) const {
			return Path::Combine(WorkingDirectory, path);
		}
		
		void Resolve() {
			ConfigFile = ResolvePath(ConfigFile).ToString();
			if (!PidFile.IsEmpty()) {
				PidFile = ResolvePath(PidFile).ToString();
			}
			if (!LogFile.IsEmpty()) {
				LogFile = ResolvePath(LogFile).ToString();
			}
		}
		
		void Dump() const {
			using namespace Ape::IO;
			B(L"ActAsDaemon:\t\t", ActAsDaemon)
			S(L"WorkingDirectory:\t", WorkingDirectory)
			S(L"ConfigFile\t\t", ConfigFile)
			S(L"LogFile\t\t", LogFile)
			S(L"PidFile:\t\t", PidFile)
			B(L"Verbose:\t\t", Verbose)
		}
	};
	
	#undef B
}


#endif // DAEMONOPTIONS_H_INCLUDED
